<template>
  <base-breadcrumb :title="$route.meta.title">
    <!-- 实测实量地图 -->
    <div id="base-breadcrumb" style="position: relative; overflow: hidden">
      <!-- 搜索 -->
      <searchData :searchData="searchArr" @search="search"></searchData>
      <!-- 表格 -->
      <a-card :bordered="false">
        <!-- <title-name :title="$route.meta.title"></title-name> -->
        <list-table
          ref="table"
          tableLayout="fixed"
          size="default"
          rowKey="projectId"
          :columns="columns"
          :request="loadData"
          :alert="true"
          show-size-changer
          show-quick-jumper
          showPagination="auto"
        >
          <span slot="action" slot-scope="text, record">
            <template>
              <a @click="handleManage(record)" v-if="hideBuquBtn()">实测实量地图维护</a>
              <a-divider type="vertical" v-if="hideBuquBtn()" />
              <a @click="handleManage(record, 1)">查看测量记录</a>
            </template>
          </span>
        </list-table>
      </a-card>
    </div>
  </base-breadcrumb>
</template>

<script>
import { STable } from '@/components' // 表格
import { map } from '@/api/quality/reality' // api
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 项目名称
import OrgTreeSelect from '@/components/OrgTreeSelect'
import SelectProjectStatus from '@/views/quality/components/SelectProjectStatus' // 项目状态

const searchArr = [
  // 搜索框
  {
    name: '所属单位',
    valueKey: 'searchQuery',
    type: OrgTreeSelect,
  },
  // {
  //   name: '分公司',
  //   type: SelectSubCompany,
  //   valueKey: 'branchCompanyId'
  // },
  // {
  //   name: '项目名称',
  //   type: SelectProject,
  //   valueKey: 'projectId'
  // },
  {
    name: '项目状态',
    type: SelectProjectStatus,
    valueKey: 'projectStatusCode',
  }
]
const columns = [
  {
    title: '分公司',
    dataIndex: 'branchCompanyName'
  },
  {
    title: '项目名称',
    dataIndex: 'projectName'
  },
  {
    title: '地图数量',
    dataIndex: 'mapNo'
  },
  {
    title: '操作',
    dataIndex: 'action',
    width: '250px',
    align: 'center',
    fixed: 'right',
    scopedSlots: { customRender: 'action' }
  }
]
export default {
  name: 'a' + Date.now(),
  components: {
    STable
  },
  data() {
    this.columns = columns
    this.searchArr = searchArr
    return {
      // 查询参数
      queryParam: {},
      // 盒子高度
      boxHeight: 0,
      // 加载数据方法 必须为 Promise 对象
      loadData: (parameter) => {
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        return map.postList(requestParameters).then((res) => {
          if (res.code === 200) {
            return res
          }
        })
      },
      editModel: 0,
      form: {}
    }
  },
  methods: {
    // 搜索
    search(value) {
      value && (this.queryParam = value)
      this.$refs.table.refresh(true)
    },
    // 操作栏
    handleManage(record, isView = 0) {
      // let query = {}
      // if (record && record.projectId) {
      //   // query.id = record.id
      //   query.projectId = record.projectId
      // }
      window.open(`/quality/measuredAmount/map/mapEdit?projectId=${record.projectId}${isView ? '&isView=1' : ''}`)
      // this.$router.push({
      //   name: '/quality/measuredAmount/map/mapEdit',
      //   query,
      // })
    }
  }
}
</script>
